
// Update the color with lowlight
vec3 DoLowlighting(in vec3 iColor)
{
  float coef = 0.55; // arbitrary coefficient to give a darker look when lowlight is activated

#ifdef LowLight_Black // Mode specific for ODT snapshot to be compliant with ORE behavior
  #ifndef Lighting
  coef = 0.0;
  #endif
#endif

  return iColor * coef;
}

#ifdef Lighting

  #ifdef FragmentStage
      // Compute the data for the standard lighting
      LightingData ComputeStdLightingData(in vec3 iP, in vec3 iN, in vec3 iView)
      {
        LightingData data;
        data.P = iP;
        data.N = iN;
        data.V = iView;
        data.visibility = 1.0;
        data.minVisibility = 0.0;

        return data;
      }

      


      // Fragment lighting compositing
      vec4 DoFragmentLightingCompositing(in LightingData data, in BRDFParameters brdf, out vec3 iblContrib)
      {
        LightingResult localRadiance = DoStdLighting(data, brdf);

        vec3 finalColor = localRadiance.radiance;
      #ifdef EVisuPBR
        float finalAlpha = localRadiance.alpha;
      #else
        float finalAlpha = 1.0 - localRadiance.transparency;
      #endif
      
        data.lightID = 0;

        #ifdef ImageBasedLighting
          finalColor += ComputeIBL(data, brdf, iblContrib);
        #endif
  
        #ifdef LightMap
          #if (LightMap == LightMapIlluminanceMode)
            finalColor += brdf.albedo * vTexture(lightMapTexture, _vPrivGetLightMapUVs()).xyz;
          #elif (LightMap == LightMapLuminosityMode)
            finalColor *= vTexture(lightMapTexture, _vPrivGetLightMapUVs()).xyz;
          #endif
        #endif

        #ifdef LegacyGlobalIllumination
          finalColor += brdf.albedo * _vPrivGetAmbientColor();;
        #endif

        #if !defined(PDSFX1) || defined(_PDSFX1_FS_Emissive)
          finalColor += ComputeEmissive();
        #endif

        #ifdef SO_EVISUPBR_SUBSURFACE
          finalColor += localRadiance.translucency;
        #endif

        #ifdef EVisuPBR
          if(finalAlpha > 0.0)
            finalColor /= finalAlpha;
        #endif

        return vec4(finalColor, finalAlpha);
      }

  #endif // FragmentStage
#endif // Lighting
